<include file="Public:header" />
<link href="{:C('status_url')}/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<style>
td,tr,th{padding:2px 5px;}
</style>

<script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/ueditor/ueditor.all.min.js"> </script>


<script type="text/javascript">
$(document).ready(function(){
    //实例化编辑器
	UE.getEditor('context');
});
</script>
<!-- main -->
<div class="main of">
     <div class="con" style="margin:20px auto;">
        <div>
            <a href="/admin.php?m=Admin&c=Tougao">列表</a>&nbsp;&nbsp;<a href="/admin.php?m=Admin&c=Tougao&do=add">添加</a> 
            <p><form action="/admin.php?m=Admin&c=Tougao&a=index">
            标题:<input name="title" type="text" placeholder="文章标题" value="{$_GET['title']}" /> 
            用户名:<input name="username" type="text" placeholder="用户名" value="{$_GET['username']}" /> 
            支付<select name="pay">
              <option value="">全部</option>
              <option value="1" <if condition="$_GET['pay'] eq 1"> selected="selected"</if>>已支付</option>
              <option value="-1" <if condition="$_GET['pay'] eq -1"> selected="selected"</if>>未支付</option>
            </select>
            状态<select name="status"><!-- 状态:-3=发布失败;-2=审核失败;-1=未审核;0=审核通过;1=已入库 -->
              <option value="">全部</option>
              <option value="0" <if condition="$_GET['status'] eq '0'"> selected="selected"</if>>待发布</option>
              <option value="-1" <if condition="$_GET['status'] eq -1"> selected="selected"</if>>未审核</option>
              <option value="1" <if condition="$_GET['status'] eq 1"> selected="selected"</if>>已发布</option>
              <option value="-2" <if condition="$_GET['status'] eq -2"> selected="selected"</if>>审核失败</option>
              <option value="-3" <if condition="$_GET['status'] eq -3"> selected="selected"</if>>发布失败</option>
            </select>
            <input type="hidden" name="m" value="Admin" />
            <input type="hidden" name="c" value="Tougao" />
            <input name="" type="submit" />
            </form></p>
        </div>
        <hr />
        <div class="article">
        <if condition="$data['do'] eq 'add'">
        <p><b><if condition="$data['info']['id']">编辑<else />添加</if></b></p>
        
        <form method="post" id="form" action="/admin.php?m=Admin&c=Tougao&do=save" data-status="1">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" style="width:980px;">
          <tr>
            <td width="8%"><div align="right">标题</div></td>
            <td width=""><input type="text" name="title" id="title" value="{$data['info']['title']}" style="padding:5px; width:400px; margin:5px;" placeholder="5~30字内" /><span id="titlebar"></span></td>
          </tr>
          <tr>
            <td><div align="right">url</div></td>
            <td><input type="text" name="url" id="url" value="{$data['info']['url']}" style="padding:5px; width:400px; margin:5px;"  placeholder="必须字母开头+只能字母和数字(建议用标题简写的全拼)" /><span id="urlbar"></span></td>
          </tr>
          <tr>
            <td><div align="right">分类</div></td>
            <td>
              <select name="cid" id="cid" style="padding:5px; margin:5px;">
              <option value="" >请选择</option>
              <volist name="data['category']['list']" id="val">
                <option value="{$val['id']}"<if condition="$data['info']['cid'] eq $val['id']"> selected="selected"</if>>{$val['name']}</option>
              </volist>
              </select>            </td>
          </tr>
          <tr>
            <td><div align="right">关键词</div></td>
            <td><input type="text" name="tag" id="tag" value="{$data['info']['tag']}" style="padding:5px; width:400px; margin:5px;" placeholder="3~5个关键字,用逗号或者空格分隔"  /><span id="tagbar"></span></td>
          </tr>
          <tr>
            <td><div align="right">封面</div></td>
            <td>
                <div class="tupian" onclick="$('.uploadBtn').click();" style="cursor:pointer; width:100px; margin:5px; height:100px; background:#ccc;"><if condition="$data['info']['thumb']"><img src="{$data['info']['thumb150']}" style="max-width:100px; max-height:100px;" border=0 /><else />点击上传</if></div>            </td>
          </tr>
          <tr>
            <td valign="top"><div align="right">内容</div></td>
            <td><textarea name="context" id="context" class="context" style="width:900px; height:500px; margin:5px;">{$data['info']['context']}</textarea></td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td><input type="submit" name="button" id="button" value="提交" style="padding:5px 10px; cursor:pointer; margin:5px;" />
              <a href="javascript:" onclick="if(confirm('确定放弃吗？内容可能会丢失')){ location.href='/admin.php?m=Admin&c=Tougao&'} return">取消</a>
              <input name="id" type="hidden" id="id" value="{$data['info']['id']}" />
              <input type="hidden" name="thumb" value="{$data['info']['thumb']}" /> 
              <input name="status" type="hidden" id="status" value="0" />           </td>
          </tr>
        </table>
        </form>
        <form method="post" class="uploadImageForm" enctype="multipart/form-data" class="hide" target="iframe-form" action="/?c=Upload&a=upload">
        <input type="file" name="upload" class="uploadBtn hide"  />
        <input type="hidden" name="dir" value="yanghua" />
        </form>
        <elseif condition="$data['do'] eq 'comment'" />
        <form method="post" action="/admin.php?m=Admin&c=Tougao&do=save">
        	<p>批注</p>
            <p><textarea name="comment">{$data['info']['comment']}</textarea></p>
        	<p><input type="submit" name="button" id="button" value="提交" style="padding:5px 10px; cursor:pointer; margin:5px;" /><input name="id" type="hidden" id="id" value="{$data['info']['id']}" /><input name="status" type="hidden" id="status" value="-2" /></p>
        </form>
        <else />
        <p><b>文章列表</b></p>
        
        <table width="100%" border="1" style="width:99%;" cellpadding="0" cellspacing="0" >
          <tr>
            <th width="">标题</th>
            <th width="100px">分类</th>
            <th width="160px">最后修改时间</th>
            <th width="160px">支付</th>
            <th width="60px">作者</th>
            <th width="50px">状态</th>
            <th width="50px">操作</th>
          </tr>
          <volist name="data['article']['list']" id="val" empty='暂无文章'>
          <tr>
            <td>{$val['title']}</td>
            <td>{$val['cid']}</td>
            <td title="发表时间：{$val['createtime']}">{$val['updatetime']}</td>
            <td><if condition="!$val['pay']"><a href="/admin.php?m=Admin&c=Tougao&a=setPay&id={$val['id']}">未支付</a><else />{$val['pay']}</if></td>
            <td>{$val['user']['username']}</td>
            <td><if condition="$val['status'] eq -1"><a href="/admin.php?m=Admin&c=Tougao&a=setStatus&id={$val['id']}" title="点击通过审核" style="color:#FF6600">未审核</a><elseif condition="$val['status'] eq -2" /><span style="color:red;">未通过</span><elseif condition="$val['status'] eq 0" /><a href="/admin.php?m=Admin&c=Tougao&a=saveToArticle&id={$val['id']}" title="点击加入正式库">待入库</a><elseif condition="$val['status'] eq 1" />已入库<elseif condition="$val['status'] eq 0" />异常</if></td>
            <td><if condition="$val['status'] lt 1"><a href="/admin.php?m=Admin&c=Tougao&do=add&id={$val['id']}">编辑</a> <a href="/admin.php?m=Admin&c=Tougao&do=comment&id={$val['id']}" title="设为未通过">退回</a><else /><span style="color:#ccc">编辑</span></if></td>
          </tr>
          </volist>
        </table>
        <p><if condition="$_GET['p'] gt 1"><a href="/admin.php?m=Admin&c=Tougao">首页</a>&nbsp;&nbsp;<a href="/admin.php?m=Admin&c=Tougao&p={$data['article']['next_page']-1}">上一页</a>&nbsp;&nbsp;<else /></if> <if condition="$data['article']['next_page']"><a href="/admin.php?m=Admin&c=Tougao&p={$data['article']['next_page']}">下一页</a>&nbsp;&nbsp;</if></p>
        </if>
        </div>
        <script>
        $(document).ready(function(){	

            $('.uploadBtn').on('change',function(){
                var editForm = $('.uploadImageForm');
                //$.jBox.tip('Loading...','loading');
                //editForm.find('.tupian').html('上传中...');
                $('.uploadImageForm').submit();
            });
			
			//检查标题
			$('#title').blur(function(){
				var title = $(this).val();
				if(title.length>50 || title.length<3){
					$('#titlebar').html('<b style="color:red;">标题必须是3~50个长度</b>');
					$('#form').attr('data-status',0);
					return false;
				}else{
					$('#titlebar').html('ok');
					$('#form').attr('data-status',1);
				}		
			});
			
			//检查关键字
			$('#tag').blur(function(){
				var tag = $(this).val();
				if(!tag.length){
					$('#tagbar').html('<b style="color:red;">关键字用逗号分隔</b>');
					$('#form').attr('data-status',0);
					return false;
				}else{
					$('#tagbar').html('ok');
					$('#form').attr('data-status',1);
				} 
			});
			
			//检查url
			$('#url').blur(function(){
				var id = $('#id').val();
				var _url = $(this).val();
				var url = '/?c=Ajax&a=tougao&do=checkurl&url='+_url+'&id='+id;

				if(!/^[a-z][a-z0-9]{2,49}$/.test(_url)){
					$('#urlbar').html('<b style="color:red;">url必须是字母开头,3~50个长度</b>');
					return false;
				}
				$('#urlbar').html('检查中...');
				$.get(url,function(rs){
					if(rs.status == 0){
						//alert(rs.msg);
						$('#urlbar').html('<b style="color:red;">'+rs.msg+'</b>');
						$('#form').attr('data-status',0);
						return false;
					}else{
						$('#urlbar').html('ok');
						$('#form').attr('data-status',1);
					}
				});
			
			});
			
			//提交检查
			$('#form').submit(function(){
				var status = $(this).attr('data-status');
				var cid = $('#cid').val();
				if(!cid){
					alert('分类不能空');
					return false;
				}
				if(status != 1){
					alert('请检查每项是否正确');
					return false;
				}
			});
        });
        //上传成功回调
        function uploadCallBack(domain,path){
            var editForm = $('#form');
            editForm.find('[name=thumb]').val(path);
            editForm.find('.tupian').html('<img src="'+domain+path+'" style="max-width:100px; max-height:100px;" border=0 />');
            //alert('封面上传成功');
        }
        </script>
        <iframe id="iframe-form" name="iframe-form" src="" class="hide" ></iframe>
</div>
<p align="center">请用最新的谷歌或者火狐浏览器</p>

</div>        

<include file="Public:footer" />
